#coding=utf-8
import sys
from com.jumang.content.BaseCheck import BaseCheck
import time
import subprocess

class Schedule(BaseCheck):
    type='schedule'
    def __init__(self,fullString,event):
        BaseCheck.__init__(self,fullString,event)
        elements=fullString.split('||')
        if len(elements)==4:
          #self.server=elements[3].strip()
          self.server=unicode(elements[3].strip(),'utf-8')
          self.errorNo=0
          self.errorInfo=''
        else:
          print 'Error: '+fullString

    def forceCheck(self):
      pass
      
    def check(self):
      self.errorNo=0
      self.errorInfo=''
      try:
        subprocess.Popen(self.server)
      except:
        self.errorNo=-666
        self.errorInfo=sys.exc_info()[1]
      return (self.errorNo,self.errorInfo)
        
#test=Schedule(r'aa||aa||aa||d:\aa.bat >> d:\aa.txt',None)
#print test.check()